home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 10527 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.1 KB

  1. Path: erich.triumf.ca!bennett
  2. From: bennett@erich.triumf.ca (P.Bennett)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Pointers to register
  5. Date: 18 Mar 1996 07:59 PST
  6. Organization: TRIUMF: Tri-University Meson Facility
  7. Distribution: world
  8. Message-ID: <18MAR199607594276@erich.triumf.ca>
  9. References: <1239@altheim.win-uk.net>
  10. NNTP-Posting-Host: erich.triumf.ca
  11. News-Software: VAX/VMS VNEWS 1.50    
  12.  
  13. In article <1239@altheim.win-uk.net>, broldham@altheim.win-uk.net (Brian R. Oldham) writes...
  14. >A couple of weeks ago someone posted the opinion that all objects in
  15. >memory must have an address, which might have gone uncontested but for
  16. >the fact that he added that therefore all pointers must point to an
  17. >address. Someone else reminded us that registers don't have an address.
  18. >Bearing in mind the usual way to assign a pointer:
  19. >    ptr = &var;
  20. >is correct for objects in memory, but how do you assign a pointer
  21. >to a register? 
  22.  
  23. You don't - a register doesn't have a memory address.
  24.  
  25. >The following function (a getch() for x86) works: But is it right??
  26.  
  27. >static union REGS inregs, outregs;
  28.  
  29. >void getkey(int *scancode, char *ch) 
  30. >{
  31. >    inregs.h.ah = 0x00;
  32. >    int86(KEYBD,&inregs,&outregs);
  33. >    *scancode = outregs.h.ah;     /* ??? */
  34.  
  35. This is not referencing a register - outregs is a union the compiler provides
  36. to allow the user to provide the values used to set the registers before
  37. calling int86(), or to store the return values from that function.
  38.  
  39. If you declare a variable as:
  40.     register int i;
  41. you are promising the compiler that you will not try to create a pointer to i,
  42. and also suggesting that the compiler may want to put i in a processor
  43. register, rather than on the stack ( or whereever it would otherwise go).
  44.  
  45.  
  46. Peter Bennett VE7CEI                | Vessels shall be deemed to be in sight
  47. Internet: bennett@triumf.ca         | of one another only when one can be
  48. Packet: ve7cei@ve7kit.#vanc.bc.ca   | observed visually from the other
  49. TRIUMF, Vancouver, B.C., Canada     |                          ColRegs 3(k)
  50. GPS and NMEA info and programs: ftp://sundae.triumf.ca/pub/peter/index.html
  51. or: ftp://ftp-i2.informatik.rwth-aachen.de/pub/arnd/GPS/peter/index.html
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.